<?php

namespace App\Http\Controllers;

use App\CodeResponse;
use App\Models\Favorite;
use App\Models\Resume;
use Illuminate\Http\Request;

class UserController extends WxController
{
    public function __construct()
    {
        //验证 token except：排除掉不需要验证的方法
        $this->middleware('checkToken');
    }

    public function Resume(){
        $data = (new Resume())->getDetailByUserId(auth('api')->id());
        return $this->success($data);
    }

    public function getDetail(){

    }

    //我的收藏
    public function getFavorite(){
        $data = (new Favorite())->getFavorite(auth('api')->id());
        return $this->success($data);
    }
    //收藏
    public function setFavorite(Request $request){
        $jobId = $request['id'];
        if (!$this->isCan($jobId)){
            return $this->fail(CodeResponse::GOODS_UNSHELVE);
        }
        (new Favorite())->setFavorite(auth('api')->id(),$jobId);
        return $this->success();
    }

    //判断是否收藏过
    public function isCan($jobId){
        $res = (new Favorite())->getIdByJobId(auth('api')->id(),$jobId);
        if ($res){
            return false;
        }
        return true;
    }

}
